char *ltrim(char *s)
{
    while(isspace(*s)) s++;
    return s;
}

char *rtrim(char *s)
{
    char* back = s + strlen(s);
    while(isspace(*--back));
    *(back+1) = '\0';
    return s;
}

char *trim(char *s)
{
    return rtrim(ltrim(s)); 
}

int readLatticeDimension(char filename[]){
/* 
     * Read the dimension of the lattice.
 */
int LATTICE_DIMENSION=0;
FILE *file = fopen ( filename, "r" );
char *pch;
if ( file != NULL )
{
   char line [ 128 ]; /* or other suitable maximum line size */
   fgets ( line, sizeof line, file ); /* read a line */
       pch = strtok (line,",");
       LATTICE_DIMENSION = strlen(pch);
       if(DEBUG)
       printf("Lattice dimension = %d\n", LATTICE_DIMENSION);
       fclose ( file );
}
else
{
   perror ( filename ); /* why didn't the file open? */
}
return LATTICE_DIMENSION;
}

